/*
var UserAdminSelectedRow;
		
function onUserAdminEditorContextMenu(grid, rowIndex, e) {
    e.stopEvent();
    var coords = e.getXY();
    UserAdminContextMenu.rowRecord = grid.store.getAt(rowIndex);
    grid.selModel.selectRow(rowIndex);
    UserAdminSelectedRow=rowIndex;
    UserAdminContextMenu.showAt([coords[0], coords[1]]);
}

UserAdminContextMenu = new Ext.menu.Menu({
    id: 'UserAdminContextMenu',
	items: [
  		{ text: 'Modify this President', handler: modifyPresidentContextMenu },
  		{ text: 'Delete this President', handler: deletePresidentContextMenu },
  		'-',
  		{ text: 'Print this grid', handler: printListingContextMenu }
	]
}); 
*/

var langAdminWindows = new Array();

MyDesktop.LangAdmin = Ext.extend(Ext.app.Module, {

    init : function(){
        this.launcher = {
            text: _('Language Administration'),
            iconCls: 'language',
            handler : this.createWindow,
            windowId : 'LangAdmin',
            scope: this
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var winname = src.windowId;
        var win = desktop.getWindow(winname);

        if(!win){
			var ds = new Ext.data.Store({
				proxy: new Ext.data.HttpProxy({
					url: getMainUrl(),
					method: 'POST'
					}),
					baseParams: {action: 'lang_admin'},
				reader: new Ext.data.JsonReader({
						root: 'results'
					},[
					{name: 'id'},
					]),
			});
			
			var sm = new Ext.grid.CheckboxSelectionModel(
			);
			
			var cm = new Ext.grid.ColumnModel(
				[sm,{
					header: _('Code'),
					readOnly: true,
					dataIndex: 'id',
					hidden: false
				}]
			);
			
			cm.defaultSortable = true;

			var admEd = new Ext.grid.GridPanel({
				id: 'langAdmGrid',
				loadMask: {msg: _('Loading...')},
				store: ds,
				cm: cm,
				selModel: sm,
				tbar: [{
					text: _('Remove'),
					iconCls: 'remove',
					handler: function() {
							if (admEd.selModel.getCount()>0) {
								Verbum.Util.confirm(_('Sure?'), function() {
										var selModel = admEd.selModel;
										var selections = selModel.getSelections();
									  	var prez = [];
									  	for(i = 0; i< selModel.getCount(); i++){
											prez.push(selections[i].json.id);
									  	}
									  	var encoded_array = Ext.encode(prez);
		
									  	var util = new Verbum.Utilities();
										util.request({
											el: admEd.getEl(),
											msg: _('Saving...'),
								            params: { 
								               action: "lang_admin", 
								               ids:  encoded_array,
								               op: 'rm'
								              }											
										});

										util.on({
											'done': function() {
												ds.reload();
											}
										});
								});	
							} else {
								Ext.Msg.message(_('Please, select an item from the list.'));
							}

						}
				},'-',{
					text: _('Add'),
					iconCls: 'add',
					handler: function() {
						
						if (langAdminWindows[0]) {
							Ext.destroy(langAdminWindows[0]);	
						}

						var ed = new Verbum.EditWindow({
							id: 'landEd',
							autoLoad: getMainUrl('action=lang_admin&op=new'),
							url: getMainUrl('action=lang_admin&op=save'),
							title: _('Add'),
				            width: 320,
				            height: 150,
				            iconCls: 'add',	
				            focus: 'id',								
						});
						ed.show();

						ed.on({
							'success': function() {
								ds.reload();
							}
						});
						
						langAdminWindows[0] = ed.current;
					}
				}]	
			});

            win = desktop.createWindow({
				id: winname,
				title: src.text,
				closable:true,
				width:380,
				height:350,
				plain:true,
				layout: 'fit',
				iconCls: 'language',
				items: admEd
            });

			win.on({
				'close': {
					fn: function() {
						for (i=0;i<langAdminWindows.length;i++) {
							Ext.destroy(langAdminWindows[i]);	
						}
					}
				}
			});

            ds.load();

        }
          
        win.show();
    },
	display : function(){
        this.createWindow();
	}
});
